Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Push — master ( 8abdb6...83f266 )
by Pierre
10:15
created

view.js ➔ define   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 81

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 11
dl 0
loc 81
rs 8.8076
c 0
b 0
f 0

7 Functions

Rating   Name   Duplication   Size   Complexity  
A view.js ➔ ... ➔ Module.extend._renderContactCollection 0 3 1
A view.js ➔ ... ➔ Module.extend._renderCredit 0 3 1
A view.js ➔ ... ➔ Module.extend.initialize 0 8 1
B view.js ➔ ... ➔ Module.extend._renderClientAddresses 0 25 2
A view.js ➔ ... ➔ Module.extend.deleteClient 0 19 1
A view.js ➔ ... ➔ Module.extend.render 0 4 1
A view.js ➔ ... ➔ Module.extend._renderClientInfo 0 9 1

How to fix   Long Method    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
/*
2
 * This file is part of CSBill package.
3
 *
4
 * (c) 2013-2015 Pierre du Plessis <[email protected]>
5
 *
6
 * This source file is subject to the MIT license that is bundled
7
 * with this source code in the file LICENSE.
8
 */
9
10
define(
11
    ['jquery', 'core/module', 'backbone', 'bootstrap.bootbox', 'routing', 'translator', 'client/view/info', './credit', './contacts', 'client/view/address_collection', 'client/model/address_collection'],
12
    function($, Module, Backbone, Bootbox, Routing, __, InfoView, ClientCredit, ClientContact, AddressView, AddressCollection) {
13
        'use strict';
14
15
        return Module.extend({
16
            regions: {
17
                'clientCredit': '#client-credit',
18
                'clientInfo': '#client-info'
19
            },
20
            _renderCredit: function(options) {
21
                this.app.showChildView('clientCredit', ClientCredit.getView(options));
22
            },
23
            _renderContactCollection: function(layoutView, options) {
24
                layoutView.renderContactsRegion(ClientContact.getView(options));
25
            },
26
            _renderClientAddresses: function(layoutView, options) {
27
                var addressCollection = new AddressCollection(options.addresses, {'id': options.id});
28
29
                var that = this;
30
31
                addressCollection.on('remove', function() {
32
                    addressCollection
33
                        .fetch({reset: true, url: Routing.generate('_xhr_clients_address_list', {'id': options.id})})
34
                        .done(function() {
35
                            layoutView.model.set('addresses', addressCollection.toArray());
36
                            options.addresses = layoutView.model.get('addresses');
37
38
                            layoutView.render();
39
                            that._renderContactCollection(layoutView, options);
40
                            if (addressCollection.length > 0) {
41
                                layoutView.getRegion('clientAddress').show(new AddressView({collection: addressCollection}));
42
                            }
43
                        }
44
                    );
45
                });
46
47
                if (addressCollection.length > 0) {
48
                    layoutView.getRegion('clientAddress').show(new AddressView({collection: addressCollection}));
49
                }
50
            },
51
            _renderClientInfo: function(options) {
52
                var infoView = new InfoView({
53
                    model: new Backbone.Model(options)
54
                });
55
56
                this.app.showChildView('clientInfo', infoView);
57
58
                return infoView;
59
            },
60
            initialize: function(options) {
61
                this._renderCredit(options);
62
63
                var infoView = this._renderClientInfo(options);
64
                this.render(infoView, options);
65
66
                $('#delete-client').on('click', this.deleteClient);
67
            },
68
            render: function(infoView, options) {
69
                this._renderContactCollection(infoView, options);
70
                this._renderClientAddresses(infoView, options);
71
            },
72
            deleteClient: function(event) {
73
                event.preventDefault();
74
75
                var link = $(this);
76
77
                Bootbox.confirm(__('client.confirm_delete'), function(confirm) {
78
                    if (true === confirm) {
79
                        $('body').modalmanager('loading');
80
81
                        $.ajax({
82
                            "url": link.attr("href"),
83
                            "dataType": "json",
84
                            "method": "delete"
85
                        }).done(function() {
86
                            window.document.location = Routing.generate("_clients_index");
87
                        });
88
                    }
89
                });
90
            }
91
        });
92
    }
93
);